package com.zlp.mall.portal.controller;


import cn.hutool.db.Page;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zlp.mall.common.api.Pager;
import com.zlp.mall.common.api.R;
import com.zlp.mall.portal.modules.oms.dto.req.OrderSubmitRep;
import com.zlp.mall.portal.modules.oms.dto.resp.OrderConfrimResp;
import com.zlp.mall.portal.modules.oms.dto.resp.OrderDetailResp;
import com.zlp.mall.portal.modules.oms.dto.resp.OrderListResp;
import com.zlp.mall.portal.modules.oms.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;


@RestController
@RequestMapping("/order")
@Api(value = "OrderController",tags = "订单模块")
public class OrderController {

    @Resource
    private  OrderService orderService;

    @PostMapping(value = "/generateConfirmOrder")
    @ApiOperation(value = "订单确认信息")
    public R<OrderConfrimResp> generateConfirmOrder(@RequestParam("itemIds") List<Long> itemIds ) {

        OrderConfrimResp orderConfrimResp = orderService.generateConfirmOrder(itemIds);
        return R.success(orderConfrimResp);
    }

    @PostMapping(value = "/generateOrder")
    @ApiOperation(value = "提交订单")
    public R generateOrder(@Valid @RequestBody OrderSubmitRep orderSubmitRep) {

        Long orderId = orderService.generateOrder(orderSubmitRep);
        return R.success(orderId);
    }


    @GetMapping(value = "/orderDetail")
    @ApiOperation(value = "获取订单明细")
    public R<OrderDetailResp> orderDetail(@RequestParam("orderId") Long orderId) {

        OrderDetailResp orderResp = orderService.orderDetail(orderId);
        return R.success(orderResp);
    }

    /**
     *  我的订单列表
     * this.axios.post('/order/list/userOrder',Qs.stringify({
     pageSize:10,
     pageNum:this.pageNum
     */
    @PostMapping(value="/list/userOrder")
    public R getMyOrders(
            @RequestParam(value="pageSize",defaultValue = "10")Integer pageSize,
            @RequestParam(value="pageNum",defaultValue = "1")Integer pageNum) {

        Pager<OrderListResp> pager = orderService.getMyOrders(pageSize, pageNum);

        return R.success(null);
    }




}

